﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace FlickrMe.Config.Registry
{
    class FlickrRegistryManager : RegistryManager
    {
        public static String getAuthKey()
        {
            RegistryKey fKey = openFlickrMeUserKey(false);
            String val = (String)fKey.GetValue("authKey");
            return val;
        }

        public static String getApiKey()
        {
            RegistryKey fKey = openFlickrMeLocalKey(false);
            String val = (String)fKey.GetValue("apiKey");
            return val;
        }

        public static String getSharedKey()
        {
            RegistryKey fKey = openFlickrMeLocalKey(false);
            String val = (String)fKey.GetValue("sharedSecret");
            return val;
        }

        public static void setAuthKey(String val)
        {
            RegistryKey fKey = openFlickrMeUserKey(true);
            fKey.SetValue("authKey", val);
        }

        /*
         * 
         */
        private static RegistryKey openFlickrMeKey(RegistryKey key, bool writeable)
        {
            RegistryKey fKey = key.OpenSubKey(@"Software\Shire Media\FlickrMe", writeable);
            return fKey;
        }

        /*
         * 
         */
        private static RegistryKey openFlickrMeUserKey(bool writeable)
        {
            RegistryKey fKey = Registry.CurrentUser;
            fKey = openFlickrMeKey(fKey, writeable);
            return fKey;
        }

        /*
        * 
        */
        private static RegistryKey openFlickrMeLocalKey(bool writeable)
        {
            RegistryKey fKey = Registry.LocalMachine;
            fKey = openFlickrMeKey(fKey, writeable);
            return fKey;
        }
    }
}
